package copyengine.dataLayer.query.server
{
	import copyengine.dataLayer.rpc.CERpcCompressManger;
	import copyengine.dataLayer.rpc.CERpcConfig;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class CEServerQuery extends Mediator
	{
		private var rpcFunctionName:String;

		private var requestObject:Object;

		private var weight:int;

		private var notificationName:String;

		public function CEServerQuery(_mediatorName:String,
									  _rpcFunctionName:String,
									  _notificationName:String,
									  _weight:int,
									  _param:Object = null)
		{
			notificationName = _notificationName;
			rpcFunctionName = _rpcFunctionName;
			if (_param != null)
			{
				requestObject = _param;
			}
			else
			{
				requestObject = {};
			}
			weight = _weight;
			super(_mediatorName, null);
		}

		override public function onRegister():void
		{
			requestObject[CERpcConfig.RPC_KEY_METHOD] = rpcFunctionName;
			CERpcCompressManger.instance.addRpcRequest(requestObject, weight);
		}

		override final public function listNotificationInterests():Array
		{
			return [
				rpcFunctionName,
				];
		}

		override final public function handleNotification(notification:INotification):void
		{
			facade.sendNotification(notificationName, notification.getBody());
			facade.removeMediator(getMediatorName());
		}

	}
}
